import java.util.*;

public class 字母异位词分组 {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> map = new HashMap<>();
        List<List<String>> ans = new ArrayList<>();
        for (String s : strs) {
            char[] ss = s.toCharArray();
            Arrays.sort(ss);
            String cur = String.valueOf(ss);
            if(!map.containsKey(cur)) {
                List<String> list = new ArrayList<>();
                list.add(s);
                map.put(cur,list);
            } else {
                List<String> list = map.get(cur);
                list.add(s);
            }
        }
        for (Map.Entry<String,List<String>> entry : map.entrySet()) {
            ans.add(entry.getValue());
        }
        return ans;
    }
}
